<template>
    <div class="top">
        <!-- 内容区 -->
        <div class="content">
            <!-- 左边区 -->
            <div class="left" @click="goHome">
                <img src="../../assets/image/logo.png" alt="">
                <p>商医通 预约挂号统一平台</p>
            </div>
            <!-- 右边区 -->
            <div class="right">
                <p class="help">帮助中心</p>
                <!-- 如果没有用户的名字：显示登录注册 -->
                <p class="login" @click="login" v-if="!UserStore.userInfo.name">登录/注册</p>
                <!-- 如果有用户信息展示用互信息 -->
                <p class="login" v-else>
                    <el-dropdown>
                        <span class="el-dropdown-link">
                            {{ UserStore.userInfo.name }}
                            <svg t="1688544968242" class="icon" viewBox="0 0 1024 1024" version="1.1"
                                xmlns="http://www.w3.org/2000/svg" p-id="2523" width="16" height="16">
                                <path
                                    d="M947.7 286.1c-15.6-15.6-40.9-15.6-56.6 0L512 665.2 132.9 286.1c-15.6-15.6-40.9-15.6-56.6 0s-15.6 40.9 0 56.6l386.6 386.6c13.5 13.5 31.3 20.3 49.1 20.3s35.6-6.8 49.1-20.3l386.6-386.6c15.6-15.6 15.6-41 0-56.6z"
                                    fill="#333333" p-id="2524"></path>
                            </svg>
                            <el-icon class="el-icon--right">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item @click="goUser('/user/certification')">实名认证</el-dropdown-item>
                                <el-dropdown-item @click="goUser('/user/order')">挂号订单</el-dropdown-item>
                                <el-dropdown-item @click="goUser('/user/patient')">就诊人管理</el-dropdown-item>
                                <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>

                </p>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import userStore from '@/store/modules/user.ts'
let UserStore = userStore()

let $router = useRouter()

// 回到主页的方法
const goHome = () => {
    $router.push({ path: '/home' })
}

// 点击登录按钮弹出对话框的方法
const login = () => {
    UserStore.visiable = true
}

const logout = ()=>{
    // 通知用户仓库清除用户相关信息
    UserStore.logout()
    // 跳转到主页面
    $router.push({path:'/home'})
}

// 跳转到user路由
const goUser =(path:string)=>{
    $router.push({path:path})
}
</script>

<style scoped lang="scss">
.top {
    position: fixed;
    z-index: 999;
    width: 100%;
    height: 70px;
    display: flex;
    justify-content: center;
    background-color: #fff;

}

.content {
    width: 1200px;
    height: 70px;
    display: flex;
    justify-content: space-between;
}

.left {
    display: flex;
    justify-content: center;
    align-items: center;

    img {
        width: 70px;
        height: 70px;
    }

    p {
        color: skyblue;
        font-size: 20px;
        font-weight: bold;
        margin-left: 10px;
    }

}

.left:hover {
    cursor: pointer;
}

.right {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    color: rgb(87, 87, 87);

    .login {
        margin: 0 10px;

        &:hover {
            color: skyblue;
            cursor: pointer;
        }
    }
}
</style>